<template>
    <div class="hello">
        <h1>{{ msg }}</h1>


        <div>
            <h1>首页</h1>
            {{ count }}
            <br/>
            <button @click="handleIncrement">+1</button>
            <button @click="handleDecrease">-1</button>
            <button @click="handleIncrementMore">+5</button>
            <div>{{ list }}</div>
            <div>{{ listCount }}</div>
            <button @click="handleActionIncrement">action +1</button>
            <button @click="handleAsyncIncrement">async +1</button>
        </div>
    </div>
</template>

<script>
	export default {
		name: 'HelloWorld',
		props: {
			msg: String
		},
		data() {
			return {}
		},
		computed: {
			count() {
				return this.$store.getters.count;
			},
			list() {
				return this.$store.getters.filteredList;
			},
			listCount() {
				return this.$store.getters.listCount;
			}
		},
		methods: {
			goBack() {
				window.history.length > 1 ? this.$router.go(-1) : this.$router.push('/')
			},
			handleIncrement() {
				this.$store.commit('increment');
			},
			handleDecrease() {
				this.$store.commit('decrease');
			},
			handleIncrementMore() {
				this.$store.commit('increment', 5);
			},
			handleActionIncrement() {
				this.$store.dispatch('increment')
			},
			handleAsyncIncrement() {
				this.$store.dispatch('asyncIncrement').then(() => {
					console.log(this.$store.state.count);
				});
			}
		}
	}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
    h3 {
        margin: 40px 0 0;
    }

    ul {
        list-style-type: none;
        padding: 0;
    }

    li {
        display: inline-block;
        margin: 0 10px;
    }

    a {
        color: #42b983;
    }
</style>
